package cn.vihub.config;

import org.checkerframework.checker.units.qual.A;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @Author: 秋晚
 * @Date: 2025/8/8 13:48
 * @Description:
 **/
@Configuration
public class RabbitmqConfig {


    /**
     * @author: 秋晚
     * @description:创建一个队列
     * @params: []
     * @return: org.springframework.amqp.core.Queue
     * @date: 2025/8/8 13:51
     */
    @Bean
    public Queue createGoodsQueue(){
        //创建一个队列
        return new Queue("goods_order_info",true);
    }


//    @Bean
//    public Queue createGoodsQueue(){
//        return new Queue("goods_info",true);
//    }


    /**
     * @author: 秋晚
     * @description:创建一个交换机
     * @params: []
     * @return: org.springframework.amqp.core.CustomExchange
     * @date: 2025/8/8 13:52
     */

    @Bean
    public CustomExchange delayExchange(){
        //定义交换机的额外参数
        Map<String, Object> args = new HashMap<>();
        //指定延迟消息最终的路由类型为direct
        args.put("x-delayed-type","direct");
        //创建自定义交换机   交换机名称  交换机类型  是否持久化  是否自动删除  额外参数
        return new CustomExchange("GoodsOrderDelayedMessage","x-delayed-message",true,false,args);
    }
//    @Bean
//    public CustomExchange delayExchange(){
//        Map<String, Object> map = new HashMap<>();
//        map.put("x-delayed-type","direct");
//        return new CustomExchange("GoodsOrderDelayedMessage","x-delayed-message",true,false, map);
//    }


    /**
     * @author: 秋晚
     * @description:绑定队列到交换机上
     * @params: [org.springframework.amqp.core.Queue, org.springframework.amqp.core.CustomExchange]
     * @return: org.springframework.amqp.core.Binding
     * @date: 2025/8/8 13:54
     */

    @Bean
    public Binding delayBinding(Queue createGoodsQueue,CustomExchange delayExchage){
        //绑定队列到交换机上
        return BindingBuilder.bind(createGoodsQueue).to(delayExchage).with("goods.order.key").noargs();
    }

//    @Bean
//    public Binding delayBinding(Queue createGoodsQueue,CustomExchange delayExchange){
//        return BindingBuilder.bind(createGoodsQueue).to(delayExchange).with("goods.order,key").noargs();
//    }

}
